<?php

namespace app\admin\model\finance;

use think\Model;

class Income extends Model
{

    // 表名
    protected $name = 'finance_income_type';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    public static function init()
    {
        /**
         * @notes 删除前
         */
        self::beforeDelete(function ($row) {
            $income = Incomelog::where(['type_id' => $row->id])->count();
            if ($income > 0) {
                throw new \think\Exception("对不起，该账户已有关联数据，不可做删除操作!");
            }
        });
    }
}
